﻿using ConfigService;
using LayeredConfig;
using LogService;
using System;
using System.IO;

namespace EmailService
{
    public class EmailServiceImp : IEmailService
    {
        private readonly ILayeredConfigInterface _configServiceLay;
        private readonly ILogService _log;

        private SenderInfo senderInfo=new SenderInfo ();
        public EmailServiceImp(ILayeredConfigInterface configService, ILogService log)
        {
            _log = log;
            _configServiceLay = configService;
        }

    

        public bool LoadSenderInfo()
        {
            senderInfo = new SenderInfo();
            senderInfo.Name = _configServiceLay.GetValue("name");
            senderInfo.PassWord = _configServiceLay.GetValue("pwd");
            return senderInfo.CheckDataVaild();
        }

        public bool SendEamil(string sendName, string toName, string body)
        {
            Console.WriteLine($"发送邮件，{sendName} to {toName } body:{body} ");
            return true;
        }

        public bool SendEamil(string toName, string body)
        {
            if (!senderInfo.CheckDataVaild())
            {
                return false;
            }
            Console.WriteLine($"伪代码发送邮件 {this.senderInfo.Name} to {toName} 内容:{body}");
            return true;
        }
    }
}
